package com.wcg.util;

import com.wcg.factory.MyFactory;
import com.wcg.factory.StaticFactory;
import com.wcg.javabean.User;
import org.junit.Test;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.util.Calendar;

public class MyTest {
    @Test
    public void u6(){
        ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext("spring.xml");
        Object u6 = applicationContext.getBean("u6");
        System.out.println(u6);
        applicationContext.close();
    }
    @Test
    public void u5(){
        ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext("spring.xml");
        Object u5 = applicationContext.getBean("u5");
        System.out.println(u5);
        applicationContext.close();
    }
    @Test
    public void u4(){
        ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext("spring.xml");
        Object u4 = applicationContext.getBean("u4");
        System.out.println(u4);
        applicationContext.close();
    }
    @Test
    public void u3(){
        ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext("spring.xml");
        Object u3 = applicationContext.getBean("u3");
        System.out.println(u3);
        applicationContext.close();
    }
    @Test
    public void myFactory(){
        //假设User类没有提供无参构造方法  只能通过MyFactory的getUser方法获取
        MyFactory myFactory=new MyFactory();
        User user = myFactory.getUser();
        ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext("spring.xml");
        Object staticFactory = applicationContext.getBean("u2");
        System.out.println(staticFactory);
        applicationContext.close();
    }
    @Test
    public void staticFactory(){
        StaticFactory s1=null;
        //s1=new StaticFactory();//没有提供任何构造方法 不能通过new关键字创建对象
        s1=StaticFactory.get();//可以通过静态方法获取对象
        ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext("spring.xml");
        Object staticFactory = applicationContext.getBean("staticFactory");
        System.out.println(staticFactory);
        applicationContext.close();
    }
    @Test
    public void test(){
        ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext("spring.xml");
        Object u1 = applicationContext.getBean("u1");
        System.out.println(u1);
        applicationContext.close();
    }
}
